import pyautogui
import time

x = 0;

def a():
    global x;
    x = 1

def rgb2hex(r, g, b):

    return '#{:02x}{:02x}{:02x}'.format(r, g, b)

if __name__ == "__main__":
    try:

        width, height = pyautogui.size()

        while True:

            time.sleep(1)

            x, y = pyautogui.position()

            rgb = pyautogui.screenshot().getpixel((x, y))

            r = str(rgb[0]).rjust(3)

            g = str(rgb[1]).rjust(3)

            b = str(rgb[2]).rjust(3)

            hex_c = rgb2hex(int(r), int(g), int(b))

            color_str = f'选中颜色 RGB:({r},{g},{b}), 16进制:{hex_c}'

            print(color_str)

    except KeyboardInterrupt:

        exit('\n\n---- Bye.\n')
